package com.jk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.dao.TbSubjectMapper;
import com.jk.dto.TbSubject;
import com.jk.pojo.PagedResponse;
import com.jk.service.TbSubjectService;
import com.jk.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yzf
 * @version 1.0
 * @description: TODO
 * @date 2024/12/11 20:17
 */
@Service
public class TbSubjectServiceImpl implements TbSubjectService {

    @Autowired
    private TbSubjectMapper tbSubjectMapper;
    @Override
    public PagedResponse<TbSubject> findSubjectList(TbSubject tbSubject, Integer pageNum, Integer pageSize) {
        Page<TbSubject> page = new Page<>(pageNum,pageSize);
        QueryWrapper<TbSubject> query = new QueryWrapper<>();
        if (null != tbSubject.getGrade() && !"".equals(tbSubject.getGrade())) {
            query.eq("grade", tbSubject.getGrade());
        }
        Page<TbSubject> tbSubjectPage = tbSubjectMapper.selectPage(page, query);
        return PaginationUtil.getPagedResponse(tbSubjectPage.getRecords(),pageNum,pageSize,tbSubjectPage.getTotal());
    }

    @Override
    public TbSubject getSubjectById(Integer id) {
        return tbSubjectMapper.selectById(id);
    }

    @Override
    public void delSubjectById(Integer id) {
        tbSubjectMapper.deleteById(id);
    }

    @Override
    public void addSubject(TbSubject tbSubject) {
        tbSubjectMapper.insert(tbSubject);
    }

    @Override
    public void upSubject(TbSubject tbSubject) {
        tbSubjectMapper.updateById(tbSubject);
    }
}
